package cn.wh.common.action;

import java.io.IOException;

import javax.servlet.http.HttpSession;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import cn.wh.common.Util.VerifyCodeUtils;

@Component("commonAction")
@Scope("prototype")
public class CommonAction extends BaseAction{

	// 验证码图片
	public String randImg() throws IOException {
		response.setHeader("Param", "No-cache");
		response.setHeader("Cache-Control", "no-cache");
		response.setDateHeader("Expires", 0);
		response.setContentType("image/jpeg");
		
		// 随机生成字符串
		String verifyCode = VerifyCodeUtils.generateVerifyCode(4);
		// 存入session 
		HttpSession session = request.getSession();
		session.setAttribute("rand", verifyCode);
		// 生成图片
		int w = 200, h = 80;
		VerifyCodeUtils.outputImage(w, h, response.getOutputStream(), verifyCode);
		
		return null;
	}
	
}
